package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.ConfigPageToCustomerMapper;
import com.tzbank.back.service.ConfigPageToCustomerService;
import com.tzbank.entity.backstage.ConfigPageToCustomer;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class ConfigPageToCustomerServiceImpl implements ConfigPageToCustomerService {

	@Autowired
	private ConfigPageToCustomerMapper configPageToCustomerMapper;

	@Override
	public Map<String, Object> getCustomer(int autoId) throws Exception{
		ConfigPageToCustomer configPageToCustomer = this.configPageToCustomerMapper.getCustomer(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), configPageToCustomer);
	}

	@Override
	public Map<String, Object> selectCustomer() throws Exception{
		List<ConfigPageToCustomer> configPageToCustomers = this.configPageToCustomerMapper.selectCustomer();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), configPageToCustomers);
	}

	@Transactional
	@Override
	public Map<String, Object> deleteCustomer(ConfigPageToCustomer customer) throws Exception{
		customer.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		customer.setStatus("0");
		this.configPageToCustomerMapper.deleteCustomer(customer);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> addCustomer(ConfigPageToCustomer customer) throws Exception{
		customer.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		customer.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.configPageToCustomerMapper.insertCustomer(customer);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> modifyCustomer(ConfigPageToCustomer customer) throws Exception {
		customer.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.configPageToCustomerMapper.updateCustomer(customer);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
